/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
import type { MenuDataItem } from '@ant-design/pro-components';
export default function access(
  initialState: { currentUser?: API.CurrentUser; permissions: API.Permissions } | undefined,
) {
  const { currentUser, permissions } = initialState ?? {};
  return {
    // 是否超级管理员
    isAdmin: currentUser ? currentUser.userid === 1 : false,
    // 菜单权限
    routeFilter: (route: MenuDataItem) =>
      !!permissions && !!permissions.menus && permissions.menus.includes(route.name),
    // 按钮权限
    btnFilter: (name: string) =>
      !!permissions && !!permissions.btns && permissions.btns.includes(name),
  };
}
